/**
* @description: 待办工单 -》 通信光缆巡视 -》 已巡视详情 -》 纤芯完善
**/

<template>
  <view class="optical-complete-wrap">
    <nav-bar class="header" back :title="`纤芯完善`" @goBack="goBack"/>
    <view class="main-container">
      <plateTitle :title="`基本信息（纤芯${opticalInfo.CORE_NAME}）`" :isRequired="false" class="plate-title"/>
      <view class="base-info-container">
        <!-- 基本信息 -->
        <van-cell-group v-for="(item, index) in currentData.baseInfo" :key="index">
          <!-- 不可编辑框 -->
          <van-cell
            v-if="item.elementType === 'TEXT'"
            :required="item.isRequired"
            readonly
            input-align="right"
            :value="item.value"
            :title="item.title"
          />
          <!-- 弹出筛选框 -->
          <van-field
            v-if="item.elementType === 'PICKER'"
            :required="item.isRequired"
            readonly
            clickable
            input-align="right"
            right-icon="arrow"
            v-model="item.text"
            :label="item.title"
            placeholder="点击选择"
            @click="checkPickerList(item)"
          />
        </van-cell-group>
        <van-cell-group v-if="currentData.baseInfo.isOccupy.value !== ''"
                        v-for="(item, index) in currentData.baseInfo_other" :key="index">
          <!-- 特殊的弹出框，针对配对纤芯 -->
          <van-field
            v-if="item.elementType === 'CABLEPICKER'"
            :required="item.isRequired"
            readonly
            input-align="right"
            :value="item.text"
            :label="item.title"
            right-icon="arrow"
            placeholder="点击选择"
            @click="checkPairCore(item)"
          />
          <!-- 弹出筛选框 -->
          <van-field
            v-if="item.elementType === 'PICKER'"
            :required="item.isRequired"
            readonly
            clickable
            input-align="right"
            right-icon="arrow"
            v-model="item.text"
            :label="item.title"
            placeholder="点击选择"
            @click="checkPickerList(item)"
          />
          <!-- 输入框 -->
          <van-field
            v-if="item.elementType === 'INPUT'"
            :type="item.inputType"
            :required="item.isRequired"
            clickable
            input-align="right"
            :value="item.value"
            :label="item.title"
            placeholder="请输入"
            @input="inputBlur($event, item)"
          />
        </van-cell-group>
      </view>
      
      <!-- 未选择是否占用时，不显示任何信息 -->
      <div v-if="currentData.baseInfo.isOccupy.value !== ''">
        <!-- 是否占用  已经占用才需要填写光路信息 -->
        <view class="optical-info-container"
              v-if="currentData.baseInfo.isOccupy.value !== '5' && currentData.baseInfo.isOccupy.value !== '6'">
          <plateTitle title="光路信息" :isRequired="false" class="plate-title-2"/>
          <view class="switch optical-info-item">
            <van-field name="switch" label="光路A端与Z端设备信息可现场确认" input-align="right">
              <template #input>
                <van-switch @change="checkIsConfirm" v-model="currentData.equipmentInfo.isConfirm.realVal" size="20"
                            active-color="#417ADC"/>
              </template>
            </van-field>
          </view>
          <!-- 不能确认光路信息时，不进行光路信息设备的展示 -->
          <view v-if="currentData.equipmentInfo.isConfirm.realVal">
            <view class="end-item optical-info-item">
              <van-collapse v-model="activeName">
                <van-collapse-item title="A端设备" name="equipment" :icon=iconUrl size="large" :is-link="false" disabled>
                  <van-cell-group v-for="(item, index) in currentData.equipmentInfo.A" :key="index">
                    <!-- 不可编辑框 -->
                    <van-field
                      :required="item.isRequired"
                      readonly
                      input-align="right"
                      :value="item.value"
                      :label="item.title"
                      right-icon="arrow"
                      placeholder="点击选择"
                      @click="checkInfo(item)"
                    />
                  </van-cell-group>
                </van-collapse-item>
              </van-collapse>
            </view>
            <view class="end-item optical-info-item">
              <van-collapse v-model="activeName">
                <van-collapse-item title="Z端设备" name="opticalCable" :icon=iconUrl size="large" :is-link="false"
                                   disabled>
                  <van-cell-group v-for="(item, index) in currentData.equipmentInfo.Z" :key="index">
                    <!-- 不可编辑框 -->
                    <van-field
                      :required="item.isRequired"
                      readonly
                      input-align="right"
                      :value="item.value"
                      :label="item.title"
                      right-icon="arrow"
                      placeholder="点击选择"
                      @click="checkInfo(item)"
                    />
                  </van-cell-group>
                </van-collapse-item>
              </van-collapse>
            </view>
            <!-- 主备光路 -->
            <view class="end-item optical-info-item">
              <van-collapse v-model="activeName">
                <van-collapse-item title="主备光路" name="mainPrepare" :icon=iconUrl size="large" :is-link="false" disabled>
                  <!-- 弹出筛选框 -->
                  <van-field
                    :required="currentData.equipmentInfo.mainPrepare.isRequired"
                    readonly
                    clickable
                    input-align="right"
                    right-icon="arrow"
                    v-model="currentData.equipmentInfo.mainPrepare.text"
                    :label="currentData.equipmentInfo.mainPrepare.title"
                    placeholder="点击选择"
                    @click="checkPickerList(currentData.equipmentInfo.mainPrepare)"
                  />
                </van-collapse-item>
              </van-collapse>
            </view>
            <!-- 光路部分 -->
            <view class="optical-info-item">
              <van-field
                :required="currentData.lightPathInfo.lightName.isRequired"
                readonly
                input-align="right"
                value=""
                :label="currentData.lightPathInfo.lightName.title"
              >
                <template #button>
                  <span style="color: #417adc;" @click="checkInfo(currentData.lightPathInfo.lightName)">匹配光路</span>
                </template>
              </van-field>
              <van-field
                :value="currentData.lightPathInfo.lightName.value"
                rows="1"
                autosize
                readonly
                type="textarea"
                placeholder="请点击匹配光路"
              />
              <!-- 不可编辑框 -->
              <van-field
                :required="currentData.lightPathInfo.A.isRequired"
                readonly
                input-align="right"
                :value="currentData.lightPathInfo.A.text"
                :label="currentData.lightPathInfo.A.title"
              />
              <!-- 不可编辑框 -->
              <van-field
                :required="currentData.lightPathInfo.Z.isRequired"
                readonly
                input-align="right"
                :value="currentData.lightPathInfo.Z.text"
                :label="currentData.lightPathInfo.Z.title"
              />
            </view>
          </view>
        
        </view>
        
        <plateTitle title="巡视信息" :isRequired="false" class="plate-title-2"/>
        <!-- 未占用时，不显示本端现场标签内容 -->
        <view class="remark-info-container" v-if="currentData.baseInfo.isOccupy.value !== '5'">
          <view>
            <span style="font-size: 14px; color: #ee0a24" v-if="currentData.tourInfo.otherProps.label.isRequired">*</span>
            本端现场标签内容
          </view>
          <van-divider dashed/>
          <view class="remark-wrap">
            <textarea class="remark-text" v-model="currentData.tourInfo.otherProps.label.value">
            </textarea>
          </view>
        </view>
        
        <!-- 巡视照片 -->
        <view class="patrol-info-container">
          <view>巡视照片</view>
          <van-divider dashed/>
          <div class="image-wrap">
            <div class="image-list">
              <div
                class="upload-button"
                v-for="(imgItem, index) in files"
                :style="{'background-image': `url(${imgItem.bgImg})`}"
                @click.stop="imageHandle(imgItem, index, 'CHOOSE')"
              >
                <div v-if="imgItem.img" class="delete-icon" @click.stop="imageHandle(imgItem, index, 'DELETE')">×</div>
                <img v-if="imgItem.img" :src="imgItem.img" alt="" @click.stop="imageHandle(imgItem, index, 'PREVIEW')">
              </div>
            </div>
          </div>
        </view>
        
        
        <!-- 备注 -->
        <view class="remark-info-container">
          <view>备注</view>
          <van-divider dashed/>
          <view class="remark-wrap">
            <textarea class="remark-text" v-model="currentData.tourInfo.otherProps.remark.value">
            </textarea>
          </view>
        </view>
        
        <view class="result-info-container">
          <van-cell-group>
            <van-cell v-for="(item,index) in currentData.tourInfo.inspectorInfo" :key="index" :title="item.title" :value="item.value"/>
          </van-cell-group>
        </view>
        
        
        <van-button block @click="submit">保存</van-button>
      </div>
    
    </view>
    
    <!--选择器-->
    <van-popup v-model="showPicker" position="bottom">
      <van-picker
        :default-index="defaultPickerIndex"
        show-toolbar
        :columns="currentPickerList"
        cancel-button-text="清空"
        @confirm="pickerConfirm"
        @cancel="pickerEmpty"
      >
        <template #option="item">
          <div class="picker-option corepdId-picker"  v-if="currentChangeItem === 'corePdId'">
            <div>{{ item.text }}</div>
            <!--纤芯未占用或无占用状态时，显示空，否则显示光路名称-->
            <div class="circuit">
              {{ item.origin.IS_OCCUPY === undefined || item.origin.IS_OCCUPY === "5" ? "" : item.origin.occupy_state }}
            </div>
            <!--              <div class="circuit">1000kV11至11光缆1000kV11至11光缆1000kV11至11光缆1000kV11至11光缆</div>-->
            <div style="width: 16px;">
              <!-- <van-icon name="success" v-show="saveParams.line_match_name === item.text" color="#417ADC"/> -->
            </div>
          
          </div>

          <div class="picker-option lightName-picker" v-else-if="currentChangeItem === 'lightName'">
            <div class="light-option">{{ item.text }}</div>
          </div>

          <div class="picker-option other-picker" v-else>
            <div class="default-option">{{ item.text }}</div>
          </div>
        </template>
      </van-picker>
    </van-popup>
    
    <!--选择设备选择器-->
    <van-popup v-model="showSelectEquipment" position="right">
      <select-equipment :equObj="selectEqumentOption" @cancel="equCancel" :selected.sync="equKeys"
                        @changeSelected="changeEquSelected($event)"/>
    </van-popup>
    
    <van-popup class="van-preview-wrap" v-model="showPreview" @click="showPreview = false">
      <van-swipe>
        <div v-for="(image, index) in files" :key="index">
          <van-swipe-item v-if="image.img" style="text-align: center;">
            <div style="width: 100%; text-align: center;">{{ image.previewName }}</div>
            <img :src="image.img"/>
          </van-swipe-item>
        </div>
      </van-swipe>
    </van-popup>
  </view>
</template>

<script>
// 未占用
let baseInfo_unoccupied = {
  "length": { // 测试长度
    title: "测试长度(Km)",
    keys: "length",
    value: "",
    isRequired: false,
    inputType: "number",
    elementType: "INPUT",
  },
  "loss": { // 全程总损耗
    title: "全程总损耗(dB)",
    keys: "loss",
    value: "",
    isRequired: false,
    inputType: "number",
    elementType: "INPUT",
  },
  "isSmoothness": { // 配对纤芯id
    title: "曲线是否平滑",
    keys: "isSmoothness",
    value: "",
    text: "",
    isRequired: false,
    defaultPickerIndex: 0,
    elementType: "PICKER",
    inputType: "text",
    optionsList: []
  },
  "breakpoint": {
    title: "断点位置",
    keys: "breakpoint",
    value: "",
    isRequired: false,
    inputType: "text",
    elementType: "INPUT",
  }
};
// 已占用
let baseInfo_occupy = {
  "corePdId": { // 配对纤芯id
    title: "配对纤芯",
    keys: "corePdId",
    value: "",
    text: "",
    isRequired: false,
    elementType: "CABLEPICKER",
    optionsParams: {kdCode: "OPTICALORDER"}
  },
};
// 基本信息
let opticalInfo = {
  baseInfo: { // 基本信息
    "theirCable": { // 所属光缆
      title: "所属光缆",
      keys: "theirCable",
      value: "",
      isRequired: true,
      elementType: "TEXT",
    },
    "isOccupy": { // 纤芯是否占用
      title: "是否占用",
      keys: "isOccupy",
      defaultPickerIndex: 0,
      text: "",
      value: "",
      isRequired: true,
      elementType: "PICKER",
      optionsList: [], // 下拉列表
    },
  },
  baseInfo_other: { // 其他基本信息，业务关系，由是否占用的选项决定补丁方式
  
  },
  equipmentInfo: { // 设备信息
    A: {
      "aEquName": {
        title: "设备名称",
        keys: "aEquName",
        text: "",
        value: "",
        isRequired: true,
        elementType: "TEXT",
        siteId: '', // 所属站点id
        relevance: [ // 关联
          {
            keys: "aShelf",
            paramKeys: "A_SHELF",
            value: null,
          },
          {
            keys: "aSlot",
            paramKeys: "A_SLOT",
            value: null,
          },
          {
            keys: "aPort",
            paramKeys: "A_PORT",
            value: null
          }
        ], // 关联
      },
    },
    Z: {
      "zEquName": {
        title: "设备名称",
        keys: "zEquName",
        text: "",
        value: "",
        isRequired: true,
        elementType: "TEXT",
        siteId: '', // 所属站点id
        relevance: [ // 关联
          {
            keys: "zShelf",
            paramKeys: "Z_SHELF",
            value: null,
          },
          {
            keys: "zSlot",
            paramKeys: "Z_SLOT",
            value: null,
          },
          {
            keys: "zPort",
            paramKeys: "Z_PORT",
            value: null
          }
        ], // 关联
      },
    },
    "mainPrepare": {
      title: "主备光路",
      keys: "mainPrepare",
      defaultPickerIndex: 0,
      value: "",
      text: "",
      isRequired: true,
      elementType: "PICKER",
      optionsList: [],
    },
    "isConfirm": {
      realVal: false,
      value: "0",
    }, // 是否可以确认信息   0为不可以1为可以
  },
  // 光路信息
  lightPathInfo: {
    "lightName": {
      title: "光路名称",
      keys: "lightName",
      value: "",
      isRequired: true,
      elementType: "PICKER",
      optionsList: [],
    },
    // A端设备匹配后的框槽端口
    A: {
      title: "A端设备端口",
      keys: "lightName",
      text: "",
      value: null,
      isRequired: false,
      elementType: "TEXT",
      
    },
    Z: {
      title: "Z端设备端口",
      keys: "lightName",
      text: "",
      value: null,
      isRequired: false,
      elementType: "TEXT",
    }
  },
  // 巡视补充信息
  tourInfo: {
    // 巡视人信息
    inspectorInfo: {
      "tourOperName": {
        title: "巡视人",
        keys: "tourOperName",
        value: "",
        isRequired: false,
        elementType: "TEXT"
      },
      "tourTime": {
        title: "巡视时间",
        keys: "tourTime",
        value: moment().format("YYYY-MM-DD HH:mm:ss"),
        isRequired: false,
        elementType: "TEXT"
      },
    },
    // 巡视信息
    otherProps: {
      "label": {
        title: "本端现场标签内容",
        keys: "label",
        value: "",
        isRequired: true,
        elementType: "TEXTAREA"
      },
      "remark": {
        title: "备注",
        keys: "remark",
        value: "",
        isRequired: false,
        elementType: "TEXTAREA"
      }
    },
  },
  hideProps: {
    objId: "", // 纤芯巡视id
    corePdArrange: "", // 配对纤芯名称
    aEquId: "", // A端设备id
    zEquId: "", // Z端设备id
    lightPathId: "", // 匹配光路的id
    tourOperId: "", // 巡视人员ID
    taskId: "", // 主工单id
    parOpt: "", // 所属光缆巡视id
  },
  
};

let fileTemplate = [
  {
    name: "EQUIPMENT.jpg",
    previewName: "设备照片",
    type: "EQUIPMENT",
    bgImg: require("../../../../../static/img/bg_shebei.png"),
    raw: null, // raw文件
    img: "", // 用来显示的照片
  },
  {
    name: "NAMEPLATE.jpg",
    previewName: "铭牌照片",
    type: "NAMEPLATE",
    bgImg: require("../../../../../static/img/bg_mingpai.png"),
    raw: null, // raw文件
    img: "", // 用来显示的照片
  },
  {
    name: "OTHER.jpg",
    previewName: "其他照片",
    type: "OTHER",
    bgImg: require("../../../../../static/img/bg_qita.png"),
    raw: null, // raw文件
    img: "", // 用来显示的照片
  },
];
import config from "../../../../../common/config";
import navBar from "../../../../../components/common/nav-bar";
import plateTitle from "../../../../../components/business/plateTitle";
import selectEquipment from "../../../../common/selectEquipment.vue";
import moment from "moment";
import axios from "axios";
import { merge } from "lodash";
import {Dialog, Toast} from "vant";
import wx from "../../../../../static/common_js/jweixin_1.0.0";

import {mapGetters} from "vuex";


export default {
  components: {navBar, plateTitle, selectEquipment},
  data() {
    return {
      baseUrl: "", // 基础url
      iconUrl: require("../../../../../static/img/end.png"),
      taskId: "", // 主工单id
      opticalInfo: "", // 纤芯信息
      currentData: {}, // 纤芯配置信息
      currentChangeItem: "", // 当前正在改动的key
      pageSource: "", // 页面来源（可能存在核查列表的跳转、或者新增光缆页面的跳转）
      showPicker: false, // 是否显示picker
      currentPickerList: [], // 当前可选的项
      activeName: ["equipment", "opticalCable", "mainPrepare"],
      files: {}, // 图片files
      delList: [], // 被删除的列表，需要和后台交互
      showPreview: false,
      equKeys: {}, // 已选设备id列表
      showSelectEquipment: false, // 展示设备选择
      selectEqumentOption: { // 选择设备组件需要的配置
        equType: "equipment",
        siteId: "", // 站点id（实际因为选择a站点和b站点，会存在两个siteid）
      },
      siteMap: {
        A_SITE_ID: "", // a站点id
        Z_SITE_ID: "", // z站点id
      },
      reTourCheck: "", // 巡视-1 重新编辑-0
      serviceState: "", // 设备状态
      defaultPickerIndex: 0, // picker默认选中索引
    };
  },
  onLoad(options) {
    this.reTourCheck = options.reTourCheck !== undefined ? options.reTourCheck : "1";
    config.getOptions.then(res => {
      console.log(res.firstUrl, "URL-----")
      this.baseUrl = res.firstUrl;
    });
    this.pageSource = options.source;
    this.currentData = JSON.parse(JSON.stringify(opticalInfo));
    this.files = JSON.parse(JSON.stringify(fileTemplate));
    
    this.taskId = options.taskId;
    this.opticalInfo = JSON.parse(options.opticalInfo);
    // 初始化巡视人信息
    this.currentData.tourInfo.inspectorInfo.tourOperName.value = this.userData.userName;
    this.currentData.tourInfo.inspectorInfo.tourTime.value = moment().format("YYYY-MM-DD HH:mm:ss");
    this.currentData.hideProps.objId = this.opticalInfo.OBJ_ID;
    this.currentData.hideProps.tourOperId = this.userData.userId;
    this.currentData.hideProps.taskId = this.taskId;
    this.currentData.hideProps.parOpt = this.opticalInfo.PAR_OPT;
    this.currentData.baseInfo.theirCable.value = this.opticalInfo.FIBER_NAME;
    
    
    // 获取可选的下拉列表
    this.getSelectList();
    // 获取a、z站点信息
    this.getSiteInfo();
    
    // 回填信息部分
    this.getEchoInfo();
  },
  computed: {
    ...mapGetters(["userData"]),
  },
  methods: {
    goBack() {
      if (this.pageSource === "addCable") {
        uni.navigateTo({
          url: `/pages/workBench/todoTask/cableTour/addCable/addCable?taskId=${this.taskId}&fiber_exam_id=${this.opticalInfo.PAR_OPT}`
        });
      } else if (this.pageSource === "cableDetail") {
        uni.navigateTo({
          url: `/pages/workBench/todoTask/cableTour/cableDetail/cableDetail?tourId=${this.opticalInfo.PAR_OPT}`
        });
      }
    },
    // 回显信息
    getEchoInfo() {
      this.$api.todoTaskApi.fiberDetail({
        line_exam_id: this.opticalInfo.OBJ_ID,
        // todo: 同步对端判断，2023.3.18要求去掉，暂时注释
        // front_line_id: this.opticalInfo.FRONT_LINE_ID || ""
        front_line_id: ""
      })
        .then((res) => {
          
          let fiberDetail = res.data.lineMessage; // 纤芯原信息
          // 第一次巡视（SERVICE_STATE不存在），设备状态默认为更新（4）
          this.serviceState = res.data.lineMessage.SERVICE_STATE === undefined ? 4 : res.data.lineMessage.SERVICE_STATE;
          this.currentData.baseInfo.theirCable.value = fiberDetail.FIBER_NAME; // 所属光缆
          this.files = this.files.map((item) => {
            return {
              ...item,
              img: res.data.lineMessage.photoMap[item.type] ? this.baseUrl + res.data.lineMessage.photoMap[item.type] : "",
            };
          });
          if (!fiberDetail.IS_OCCUPY) {
            // alert(111)
            // 是否占用未空，被认为啥都没填写过
            return;
          }
          this.currentData.baseInfo.isOccupy.text = fiberDetail.IS_OCCUPY_NAME; // 是否占用-名称
          this.currentData.baseInfo.isOccupy.value = fiberDetail.IS_OCCUPY; // 是否占用编码
          this.currentData.baseInfo.isOccupy.defaultPickerIndex = this.currentData.baseInfo.isOccupy.optionsList.findIndex(item => item.value === fiberDetail.IS_OCCUPY);
          
          if (fiberDetail.IS_OCCUPY === "5") {
            
            // 第一次完善和重新编辑分离，第一次完善，全部不要，重新编辑，回显
            if (this.reTourCheck === "1") { // 完善
              this.currentData.baseInfo_other = JSON.parse(JSON.stringify(baseInfo_unoccupied));
              this.currentData.baseInfo_other.length.value = ""; // 测试长度
              this.currentData.baseInfo_other.loss.value = ""; // 全程总损耗
              this.currentData.baseInfo_other.isSmoothness.text = ""; // 曲线是否平滑
              this.currentData.baseInfo_other.isSmoothness.value = ""; // 曲线是否平滑编码
              this.currentData.baseInfo_other.breakpoint.value = ""; // 断点位置
            } else {
              this.currentData.baseInfo_other = JSON.parse(JSON.stringify(baseInfo_unoccupied));
              this.currentData.baseInfo_other.length.value = fiberDetail.LENGTH || ""; // 测试长度
              this.currentData.baseInfo_other.loss.value = fiberDetail.LOSS || ""; // 全程总损耗
              this.currentData.baseInfo_other.isSmoothness.text = fiberDetail.IS_SMOOTHNESS_NAME || ""; // 曲线是否平滑
              this.currentData.baseInfo_other.isSmoothness.value = fiberDetail.IS_SMOOTHNESS || ""; // 曲线是否平滑编码
              this.currentData.baseInfo_other.breakpoint.value = fiberDetail.BREAKPOINT || ""; // 断点位置
            }
            
          } else if (fiberDetail.IS_OCCUPY === "6") {
            // 此纤芯收保护
            this.currentData = JSON.parse(JSON.stringify({
              baseInfo: this.currentData.baseInfo,
              baseInfo_other: {},
              equipmentInfo: {},
              lightPathInfo: {},
              tourInfo: this.currentData.tourInfo,
              hideProps: this.currentData.hideProps
            }));
            
          } else if (fiberDetail.IS_OCCUPY !== "") {
            // 此纤芯已经占用，需要读取的字段为占用时的字段
            this.currentData.baseInfo_other = JSON.parse(JSON.stringify(baseInfo_occupy));
            this.currentData.baseInfo_other.corePdId.text = fiberDetail.CORE_PD_ARRANGE || ""; // 配对纤芯名称
            this.currentData.baseInfo_other.corePdId.value = fiberDetail.CORE_PD_ID || ""; // 配对纤芯id
            this.currentData.hideProps.corePdArrange = fiberDetail.CORE_PD_ARRANGE || ""; // 配对纤芯名称
            
            // 光路信息，如果含有匹配光路名称，则判定为可以确认现场设备信息
            if (fiberDetail.LIGHT_PATH_ID) {
              // 确认按钮与信息
              this.currentData.equipmentInfo.isConfirm.realVal = true; // 是否可确认信息
              this.currentData.equipmentInfo.isConfirm.value = "1";
              // 取设备信息、光路信息
              this.currentData.equipmentInfo.A.aEquName.text = fiberDetail.A_EQU_NAME; // a端设备名称
              this.currentData.equipmentInfo.A.aEquName.value = fiberDetail.A_EQU_NAME; // a端设备名称
              this.currentData.equipmentInfo.A.aEquName.siteId = fiberDetail.A_SITE_ID;
              this.currentData.hideProps.aEquId = fiberDetail.A_EQU_ID; // a端设备id
              
              
              this.currentData.equipmentInfo.A.aEquName.relevance[0].value = fiberDetail.A_SHELF || ""; // a端框
              this.currentData.equipmentInfo.A.aEquName.relevance[1].value = fiberDetail.A_SLOT || ""; // a端槽
              this.currentData.equipmentInfo.A.aEquName.relevance[2].value = fiberDetail.A_PORT || ""; // a端口
              this.currentData.lightPathInfo.A.text = fiberDetail.A_PORT_NAME || "";// a端设备端口（合并）
              
              this.currentData.equipmentInfo.Z.zEquName.text = fiberDetail.Z_EQU_NAME; // z端设备名称
              this.currentData.equipmentInfo.Z.zEquName.value = fiberDetail.Z_EQU_NAME; // z端设备名称
              this.currentData.equipmentInfo.Z.zEquName.siteId = fiberDetail.Z_SITE_ID;
              this.currentData.hideProps.zEquId = fiberDetail.Z_EQU_ID; // z端设备id
              
              
              this.currentData.equipmentInfo.Z.zEquName.relevance[0].value = fiberDetail.Z_SHELF || ""; // z端框
              this.currentData.equipmentInfo.Z.zEquName.relevance[1].value = fiberDetail.Z_SLOT || ""; // z端槽
              this.currentData.equipmentInfo.Z.zEquName.relevance[2].value = fiberDetail.Z_PORT || ""; // z端口
              this.currentData.lightPathInfo.Z.text = fiberDetail.Z_PORT_NAME || "";// z端设备端口（合并）
              
              this.currentData.equipmentInfo.mainPrepare.value = fiberDetail.MAIN_PREPARE; // 主备光路编码
              this.currentData.equipmentInfo.mainPrepare.text = fiberDetail.MAIN_PREPARE_NAME; // 主备光路名称
              this.currentData.equipmentInfo.mainPrepare.defaultPickerIndex = this.currentData.equipmentInfo.mainPrepare.optionsList.findIndex(item => item.value === fiberDetail.MAIN_PREPARE);
              
              
              this.currentData.lightPathInfo.lightName.value = fiberDetail.LIGHT_NAME; // 匹配光路名称
              this.currentData.hideProps.lightPathId = fiberDetail.LIGHT_PATH_ID; // 匹配光路id
              
            }
          }
          
          this.currentData.tourInfo.otherProps.label.value = fiberDetail.LABEL || ""; // 本段现场标签内容
          
          this.currentData.tourInfo.otherProps.remark.value = fiberDetail.REMARK || ""; // 备注
          
        });
    },
    // 获取站点信息
    getSiteInfo() {
      // 获取a站点 和z站点 的id，根据巡视光缆id获取光缆详情拿到，通过站点id获取设备列表
      this.$api.getFiberMsgLineExam({
        fiber_exam_id: this.opticalInfo.PAR_OPT
      })
        .then(res => {
          // 光缆详情
          this.siteMap = {
            A_SITE_ID: res.data.fiberMsg.A_SITE_ID, // a站点id
            Z_SITE_ID: res.data.fiberMsg.Z_SITE_ID, // z站点id
          };
        });
    },
    // 切换是否可以确认设备信息
    checkIsConfirm(value) {
      this.currentData.equipmentInfo.isConfirm = {
        realVal: value,
        value: value ? "1" : "0"
      };
      // 当打开可以确认设备信息时，不进行标签的验证
      this.currentData.tourInfo.otherProps.label.isRequired = !value;
    },
    
    // type为TEXT的点击事件
    checkInfo(opticalItem) {
      this.currentChangeItem = opticalItem.keys;
      // 被占用的纤芯处理
      if (opticalItem.keys === "theirCable") { // 所属光缆，不做任何处理
      
      }
      
      // 光路信息lightPathInfo中的光路名称，点击进行匹配
      if (opticalItem.keys === "lightName") {
        // 检查 a端设备，z端设备，主备光路，三者缺一不可
        if (!this.currentData.hideProps.aEquId || !this.currentData.hideProps.zEquId || !this.currentData.equipmentInfo.mainPrepare.value) {
          Dialog.confirm({
            message: "缺少信息，请重新编辑",
            showCancelButton: false,
          });
          // alert("缺少信息，请重新编辑");
          return;
        }
        
        // 进行匹配
        this.$api.todoTaskApi.lineExamPerfect({
          "mainPrepare": this.currentData.equipmentInfo.mainPrepare.value,
          "aEquId": this.currentData.hideProps.aEquId,
          "zEquId": this.currentData.hideProps.zEquId
        })
          .then(res => {
            console.log(res)
            if (!res.msg) {
              Dialog.confirm({
                // title: '匹配失败',
                message: `
                  <p>网络请求失败，请重试</p>
                `,
                showCancelButton: false,
                confirmButtonText: "返回",
              });
              return;
            }
  
            if (res.code === 0) {
              Dialog.confirm({
                title: "匹配成功",
                showCancelButton: false,
              }).then(() => {

                this.currentData.lightPathInfo.lightName.optionsList = res.data.map(item => {
                  return {
                    ...item,
                    text: item.NAME,
                    value: item.NAME,
                  }
                })
                this.checkPickerList(this.currentData.lightPathInfo.lightName);

                // if (res.data.length > 1) {
                //   // 只匹配到一条  默认选中
                //   this.currentData.lightPathInfo.lightName.value = res.data.NAME;
                //   this.currentData.hideProps.lightPathId = res.data.OBJ_ID;
                //   this.currentData.lightPathInfo.A.text = res.data.A_PORT_NAME;
                //   this.currentData.lightPathInfo.Z.text = res.data.Z_PORT_NAME;
                //   this.currentData.equipmentInfo.A.aEquName.relevance = this.currentData.equipmentInfo.A.aEquName.relevance.map(item => {
                //     return {
                //       ...item,
                //       value: res.data[item.paramKeys] || ""
                //     };
                //   });
        
                //   this.currentData.equipmentInfo.Z.zEquName.relevance = this.currentData.equipmentInfo.Z.zEquName.relevance.map(item => {
                //     return {
                //       ...item,
                //       value: res.data[item.paramKeys] || ""
                //     };
                //   });
                // } else {
                //   // 匹配到多条  用户自行选择
                // }
              });
            } else {
              Dialog.confirm({
                // title: '匹配失败',
                message: `
                  <p>${res.msg}</p>
                  <p>提示：如果匹配失败，请重新确认A/Z端设备信息是否正确，如不确定设备信息可关闭设备确认按钮，填写本端现场标签信息</p>
                `,
                showCancelButton: false,
                confirmButtonText: "重新编辑",
              });
              this.emptyLightPathInfo();
            }
          })
          .catch(error => {
            console.log(error);
          });
      }
      
      // 光路信息---设备名称，点击选择设备
      if (opticalItem.keys === "aEquName") {
        this.selectEqumentOption.siteId = this.currentData.equipmentInfo.A.aEquName.siteId
          ? this.currentData.equipmentInfo.A.aEquName.siteId
          : this.siteMap.A_SITE_ID
        this.equKeys = {
          NAME: this.currentData.equipmentInfo.A.aEquName.value,
          ORGID: this.currentData.hideProps.aEquId
        }
        this.showSelectEquipment = true
      } else if(opticalItem.keys === "zEquName") {
        this.selectEqumentOption.siteId = this.currentData.equipmentInfo.Z.zEquName.siteId
          ? this.currentData.equipmentInfo.Z.zEquName.siteId
          : this.siteMap.Z_SITE_ID
        this.equKeys = {
          NAME: this.currentData.equipmentInfo.Z.zEquName.value,
          ORGID: this.currentData.hideProps.zEquId
        }
        this.showSelectEquipment = true
      }
      
      // 未被占用的光缆
    },
    // 清空匹配光路的结果
    emptyLightPathInfo() {
      // 清空匹配光路信息
      this.currentData.lightPathInfo.lightName.value = "";
      this.currentData.hideProps.lightPathId = "";
      this.currentData.lightPathInfo.A.text = "";
      this.currentData.lightPathInfo.Z.text = "";
      this.currentData.equipmentInfo.A.aEquName.relevance = this.currentData.equipmentInfo.A.aEquName.relevance.map(item => {
        return {
          ...item,
          value: ""
        };
      });
      
      this.currentData.equipmentInfo.Z.zEquName.relevance = this.currentData.equipmentInfo.Z.zEquName.relevance.map(item => {
        return {
          ...item,
          value: ""
        };
      });
    },
    // 选择设备
    changeEquSelected(value) {
      this.showSelectEquipment = false;
      this.equKeys = value;
      
      // 光路信息----A设备
      
      // 2/2新需求  光路匹配失败、设备或主备光路重新选择后，都应该清空上次匹配的光路信息，重新匹配
      
      if (this.currentChangeItem === "aEquName" && this.currentData.hideProps.aEquId !== value.ORGID) {
        this.currentData.equipmentInfo.A.aEquName.value = value.NAME;
        this.currentData.hideProps.aEquId = value.ORGID;
        this.currentData.equipmentInfo.A.aEquName.siteId = value.SITEID;
        
        this.emptyLightPathInfo();
      }
      
      // 光路信息----Z设备
      if (this.currentChangeItem === "zEquName" && this.currentData.hideProps.zEquId !== value.ORGID) {
        this.currentData.equipmentInfo.Z.zEquName.value = value.NAME;
        this.currentData.hideProps.zEquId = value.ORGID;
        this.currentData.equipmentInfo.Z.zEquName.siteId = value.SITEID;
        
        this.emptyLightPathInfo();
      }
      
    },
    // 取消设备选择
    equCancel() {
      this.showSelectEquipment = false;
    },
    // 点选配对纤芯
    // 下发信息为纤芯详情
    checkPairCore(optionItem) {
      this.$api.todoTaskApi.lineMatch({
        "fiber_exam_id": this.opticalInfo.PAR_OPT,
        "line_exam_id": this.currentData.hideProps.objId,
      }).then(res => {
        this.currentPickerList = res.data.map(item => {
          return {
            origin: item,
            text: item.CORE_NAME,
            value: item.OBJ_ID,
          };
        });
        this.defaultPickerIndex = 0;
      }).then(() => {
        this.currentChangeItem = optionItem.keys;
        this.showPicker = true;
      });
    },
    // 获取所有可选下拉列表
    getSelectList() {
      this.$api.todoTaskApi.getOpticalSelectList()
        .then(res => {
          // 拷贝给所有配置
          this.currentData.baseInfo.isOccupy.optionsList = res.data.isoccupy.map(item => ({
            text: item.TITLE,
            value: item.VALUE
          }));
          if (this.currentData.equipmentInfo) {
            this.currentData.equipmentInfo.mainPrepare.optionsList = res.data.mainprepare.map(item => ({
              text: item.TITLE,
              value: item.VALUE
            }));
          }
          //曲线是否平滑，是补全信息，暂不收录于currentData
          baseInfo_unoccupied.isSmoothness.optionsList = res.data.issmoothness.map(item => ({
            text: item.TITLE,
            value: item.VALUE
          }));
        });
    },
    checkPickerList(optionItem) {
      this.currentChangeItem = optionItem.keys;
      this.currentPickerList = optionItem.optionsList;
      this.defaultPickerIndex = optionItem.defaultPickerIndex;
      this.showPicker = true;
    },
    // picker确认选择(所有下拉)
    pickerConfirm(selectedOption) {
      
      // 2/2新需求  光路匹配失败、设备或主备光路重新选择后，都应该清空上次匹配的光路信息，重新匹配
      
      // 光路信息和基本信息等分开处理
      if (this.currentChangeItem === "mainPrepare") {
        
        
        // 主备光路替换，不同于之前时，清空之前的匹配信息
        if (this.currentData.equipmentInfo[this.currentChangeItem].value !== selectedOption.value) {
          this.currentData.equipmentInfo[this.currentChangeItem].text = selectedOption.text;
          this.currentData.equipmentInfo[this.currentChangeItem].value = selectedOption.value;
          
          // 清空匹配光路信息
          this.emptyLightPathInfo();
        }
        
      } else if (this.currentChangeItem === "corePdId") {
        this.currentData.baseInfo_other[this.currentChangeItem].text = selectedOption.text;
        this.currentData.baseInfo_other[this.currentChangeItem].value = selectedOption.origin.OBJ_ID;
        // 关联部分  配对纤芯名称
        this.currentData.hideProps.corePdArrange = selectedOption.text;
        
      } else if (this.currentChangeItem === "isSmoothness") {
        this.currentData.baseInfo_other[this.currentChangeItem].text = selectedOption.text;
        this.currentData.baseInfo_other[this.currentChangeItem].value = selectedOption.value;
      }
      
      // 切换是否占用，做特殊处理，基本信息补全
      else if (this.currentChangeItem === "isOccupy") {
        // 切换是否占用时，进行标签验证的重新处理
        this.currentData.tourInfo.otherProps.label.isRequired = true;

        // 5为未占用
        if (selectedOption.value === "5") {
          this.currentData.baseInfo_other = JSON.parse(JSON.stringify(baseInfo_unoccupied));
          this.currentData.equipmentInfo = JSON.parse(JSON.stringify(opticalInfo.equipmentInfo));
          this.currentData.lightPathInfo = JSON.parse(JSON.stringify(opticalInfo.lightPathInfo));
        } else if (selectedOption.value === "6") {
          
          // 纤芯保护
          this.currentData = JSON.parse(JSON.stringify({
            baseInfo: this.currentData.baseInfo,
            baseInfo_other: JSON.parse(JSON.stringify(baseInfo_occupy)),
            equipmentInfo: null,
            lightPathInfo: null,
            tourInfo: this.currentData.tourInfo,
            hideProps: this.currentData.hideProps,
          }));
        } else {
          if(this.currentData.baseInfo[this.currentChangeItem].value !== selectedOption.value) {
            this.currentData.baseInfo_other = JSON.parse(JSON.stringify(baseInfo_occupy));
            this.currentData.equipmentInfo = JSON.parse(JSON.stringify(opticalInfo.equipmentInfo));
            this.currentData.lightPathInfo = JSON.parse(JSON.stringify(opticalInfo.lightPathInfo));
          }
        }
        this.currentData.baseInfo[this.currentChangeItem].text = selectedOption.text;
        this.currentData.baseInfo[this.currentChangeItem].value = selectedOption.value;
        this.getSelectList();
        
      } else if (this.currentChangeItem === "lightName") {
        this.currentData.lightPathInfo.lightName.value = selectedOption.value;
        this.currentData.hideProps.lightPathId = selectedOption.OBJ_ID;
        this.currentData.lightPathInfo.A.text = selectedOption.A_PORT_NAME;
        this.currentData.lightPathInfo.Z.text = selectedOption.Z_PORT_NAME;

        this.currentData.equipmentInfo.A.aEquName.relevance = this.currentData.equipmentInfo.A.aEquName.relevance.map(item => {
          return {
            ...item,
            value: selectedOption[item.paramKeys] || ""
          };
        });

        this.currentData.equipmentInfo.Z.zEquName.relevance = this.currentData.equipmentInfo.Z.zEquName.relevance.map(item => {
          return {
            ...item,
            value: selectedOption[item.paramKeys] || ""
          };
        });
      } else {
        this.currentData.baseInfo[this.currentChangeItem].text = selectedOption.text;
        this.currentData.baseInfo[this.currentChangeItem].value = selectedOption.value;
      }
      this.showPicker = false;
    },
    // 清空已选
    pickerEmpty(selectedOption) {
      this.showPicker = false;
      // 光路信息和基本信息等分开处理
      if (this.currentChangeItem === "mainPrepare") {
        this.currentData.equipmentInfo[this.currentChangeItem].text = "";
        this.currentData.equipmentInfo[this.currentChangeItem].value = "";
        // 切换占用，做特殊处理，基本信息补全
      } else if (this.currentChangeItem === "corePdId") {
        this.currentData.baseInfo_other[this.currentChangeItem].text = "";
        this.currentData.baseInfo_other[this.currentChangeItem].value = "";
        // 关联部分  配对纤芯名称
        this.currentData.hideProps.corePdArrange = "";
        
      } else if (this.currentChangeItem === "isSmoothness") {
        this.currentData.baseInfo_other[this.currentChangeItem].text = "";
        this.currentData.baseInfo_other[this.currentChangeItem].value = "";
      } else {
        this.currentData.baseInfo[this.currentChangeItem].text = "";
        this.currentData.baseInfo[this.currentChangeItem].value = "";
      }
    },
    // 为输入框时失去焦点采集输入值
    inputBlur(value, item) {
      this.currentChangeItem = item.keys;
      this.currentData.baseInfo_other[this.currentChangeItem].value = value;
    },
    imageHandle(imgItem, imgIndex, handleType) {
      if (handleType === "CHOOSE") {
        this.choosePhoto(imgItem, imgIndex);
      } else if (handleType === "PREVIEW") {
        this.showPreview = true;
      } else if (handleType === "DELETE") {
        Dialog.confirm({
          message: `是否确认删除${imgItem.previewName}`
        })
          .then(() => {
            this.$set(this.files, imgIndex, {
              ...this.files[imgIndex],
              raw: null,
              img: ""
            });
            this.delList.includes(imgItem.type) ? null : this.delList.push(imgItem.type);
            console.log(this.delList, "delete");
            
          })
          .catch(() => {
            // on cancel
          });
      }
    },
    choosePhoto(imgItem, imgIndex) {
      let _this = this;
      wx.chooseImage({
        count: 3,
        sourceType: ["camera"],
        success: (chooseImageRes) => {
          wx.getLocalImgData({
            localId: chooseImageRes.localIds[0].toString(),
            success: function (res) {
                const localData = res.localData;
                let imageBase64 = '';
                if (localData.indexOf('data:image') == 0) {
                    //苹果的直接赋值，默认生成'data:image/jpeg;base64,'的头部拼接
                    imageBase64 = localData;
                } else {
                    //此处是安卓中的唯一得坑！在拼接前需要对localData进行换行符的全局替换
                    //此时一个正常的base64图片路径就完美生成赋值到img的src中了
                    imageBase64 = 'data:image/jpeg;base64,' + localData.replace(/\n/g, '');
                }
                
                _this.$set(_this.files, imgIndex, merge(_this.files[imgIndex], {
                   raw: _this.h5_url_to_blob(imageBase64),
                   img: imageBase64
                }));

                
                if (_this.delList.includes(imgItem.type)) {
                  _this.delList = _this.delList.filter(item => {
                    if (item === imgItem.type) {
                      return false;
                    }
                    
                    return true;
                  });
                }
            }
          });
        },
        fail: (error) => {
          console.log(error);
        }
      });
    },
    h5_url_to_blob(url) {
      let arr = url.split(',');
      let mime = arr[0].match(/:(.*?);/)[1];
      let bstr = atob(arr[1]);
      let n = bstr.length;
      let u8arr = new Uint8Array(n);
      while (n--) {
          u8arr[n] = bstr.charCodeAt(n);
      }
      return new Blob([u8arr], { type: mime });
    },
    // 提交
    /**
     * 1.纤芯被占用
     *    1.可确认信息
     *    2.不可以确认信息
     * 2.纤芯未占用
     */
    submit() {
      // 纤芯被占用(未占用值为<String>5)且可确认信息
      let baseParams = {}; // 基本参数
      let params = new FormData(); // 请求的参数params
      if (this.currentData.baseInfo.isOccupy.value !== "5" && this.currentData.equipmentInfo && this.currentData.equipmentInfo.isConfirm && this.currentData.equipmentInfo.isConfirm.realVal) {
        baseParams = {
          objId: {
            keys: "objId",
            title: "纤芯巡视id",
            value: this.currentData.hideProps.objId,
          }, // 纤芯巡视id
          isOccupy: this.currentData.baseInfo.isOccupy, // 是否占用
          corePdId: this.currentData.baseInfo_other.corePdId, // 配对纤芯id
          corePdArrange: {
            keys: "corePdArrange",
            title: "配对纤芯名称",
            value: this.currentData.hideProps.corePdArrange,
          }, // 配对纤芯名称
          lightPathId: {
            keys: "lightPathId",
            title: "匹配光路id",
            value: this.currentData.hideProps.lightPathId, // 匹配光路id
          },
          lightName: this.currentData.lightPathInfo.lightName, // 匹配光路名称
          mainPrepare: this.currentData.equipmentInfo.mainPrepare, // 主备光路
          aEquId: {
            keys: "aEquId",
            title: "A端设备id",
            value: this.currentData.hideProps.aEquId,
          }, // a端设备id
          aEquName: this.currentData.equipmentInfo.A.aEquName, // a端设备名称
          zEquId: {
            keys: "zEquId",
            title: "A端设备id",
            value: this.currentData.hideProps.zEquId,
          }, // z端设备id
          zEquName: this.currentData.equipmentInfo.Z.zEquName, // z端设备名称
          label: this.currentData.tourInfo.otherProps.label,// 本端现场标签内容
          tourOperId: {
            keys: "tourOperId",
            title: "巡视人员id",
            value: this.currentData.hideProps.tourOperId,
          }, // 巡视人员id
          tourOperName: this.currentData.tourInfo.inspectorInfo.tourOperName, // 巡视人名称
          tourTime: this.currentData.tourInfo.inspectorInfo.tourTime, // 巡视时间
          remark: this.currentData.tourInfo.otherProps.remark, // 备注
          isConfirm: {
            keys: "isConfirm",
            title: "是否可确认设备信息",
            value: this.currentData.equipmentInfo.isConfirm.value
          }, // 是否可确认设备信息
          taskId: {
            keys: "taskId",
            title: "主工单id",
            value: this.taskId
          }, // 主工单id
          parOpt: {
            keys: "parOpt",
            title: "所属光缆巡视id",
            value: this.currentData.hideProps.parOpt
          }, // 所属光缆巡视id
        };
      }
      
      // 纤芯被占用(未占用值为<String>5)且   不   可确认信息
      if (this.currentData.baseInfo.isOccupy.value !== "5" && this.currentData.equipmentInfo && this.currentData.equipmentInfo.isConfirm && !this.currentData.equipmentInfo.isConfirm.realVal) {
        baseParams = {
          objId: {
            keys: "objId",
            title: "纤芯巡视id",
            value: this.currentData.hideProps.objId,
          }, // 纤芯巡视id
          isOccupy: this.currentData.baseInfo.isOccupy, // 是否占用
          corePdId: this.currentData.baseInfo_other.corePdId, // 配对纤芯id
          corePdArrange: {
            keys: "corePdArrange",
            title: "配对纤芯名称",
            value: this.currentData.hideProps.corePdArrange,
          }, // 配对纤芯名称
          label: this.currentData.tourInfo.otherProps.label,// 本端现场标签内容
          tourOperId: {
            keys: "tourOperId",
            title: "巡视人员id",
            value: this.currentData.hideProps.tourOperId,
          }, // 巡视人员id
          tourOperName: this.currentData.tourInfo.inspectorInfo.tourOperName, // 巡视人名称
          tourTime: this.currentData.tourInfo.inspectorInfo.tourTime, // 巡视时间
          remark: this.currentData.tourInfo.otherProps.remark, // 备注
          isConfirm: {
            keys: "isConfirm",
            title: "是否可确认设备信息",
            value: this.currentData.equipmentInfo.isConfirm.value
          }, // 是否可确认设备信息
          taskId: {
            keys: "taskId",
            title: "主工单id",
            value: this.taskId
          }, // 主工单id
          parOpt: {
            keys: "parOpt",
            title: "所属光缆巡视id",
            value: this.currentData.hideProps.parOpt
          }, // 所属光缆巡视id
        };
        
      }
      
      // 纤芯未占用
      if (this.currentData.baseInfo.isOccupy.value === "5") {
        baseParams = {
          objId: {
            keys: "objId",
            title: "纤芯巡视id",
            value: this.currentData.hideProps.objId,
          }, // 纤芯巡视id
          isOccupy: this.currentData.baseInfo.isOccupy, // 是否占用
          length: this.currentData.baseInfo_other.length, // 测试长度
          loss: this.currentData.baseInfo_other.loss, // 全程总损耗
          isSmoothness: this.currentData.baseInfo_other.isSmoothness, // 曲线是否平滑
          breakpoint: this.currentData.baseInfo_other.breakpoint, // 断点位置
          // label: this.currentData.tourInfo.otherProps.label,// 本端现场标签内容  未占用时不做上传
          tourOperId: {
            keys: "tourOperId",
            title: "巡视人员id",
            value: this.currentData.hideProps.tourOperId,
          }, // 巡视人员id
          tourOperName: this.currentData.tourInfo.inspectorInfo.tourOperName, // 巡视人名称
          tourTime: this.currentData.tourInfo.inspectorInfo.tourTime, // 巡视时间
          remark: this.currentData.tourInfo.otherProps.remark, // 备注
          isConfirm: {
            keys: "isConfirm",
            title: "是否可确认设备信息",
            value: this.currentData.equipmentInfo.isConfirm.value
          }, // 是否可确认设备信息
          taskId: {
            keys: "taskId",
            title: "主工单id",
            value: this.taskId
          }, // 主工单id
          parOpt: {
            keys: "parOpt",
            title: "所属光缆巡视id",
            value: this.currentData.hideProps.parOpt
          }, // 所属光缆巡视id
        };
      }
      
      // 纤芯保护
      if (this.currentData.baseInfo.isOccupy.value === "6") {
        baseParams = {
          objId: {
            keys: "objId",
            title: "纤芯巡视id",
            value: this.currentData.hideProps.objId,
          }, // 纤芯巡视id
          isOccupy: this.currentData.baseInfo.isOccupy, // 是否占用
          corePdId: this.currentData.baseInfo_other.corePdId, // 配对纤芯id
          corePdArrange: {
            keys: "corePdArrange",
            title: "配对纤芯名称",
            value: this.currentData.hideProps.corePdArrange,
          }, // 配对纤芯名称
          label: this.currentData.tourInfo.otherProps.label,// 本端现场标签内容
          tourOperId: {
            keys: "tourOperId",
            title: "巡视人员id",
            value: this.currentData.hideProps.tourOperId,
          }, // 巡视人员id
          tourOperName: this.currentData.tourInfo.inspectorInfo.tourOperName, // 巡视人名称
          tourTime: this.currentData.tourInfo.inspectorInfo.tourTime, // 巡视时间
          remark: this.currentData.tourInfo.otherProps.remark, // 备注
          taskId: {
            keys: "taskId",
            title: "主工单id",
            value: this.taskId
          }, // 主工单id
          parOpt: {
            keys: "parOpt",
            title: "所属光缆巡视id",
            value: this.currentData.hideProps.parOpt
          }, // 所属光缆巡视id
        };
      }
      // 提交方式为xform

      
      
      // 验证
      for (let paramsKey in baseParams) {
        // 必填项验证
        if (baseParams[paramsKey].isRequired && !baseParams[paramsKey].value) {
          Dialog.confirm({
            message: `${baseParams[paramsKey].title}未填写，请重新填写后提交`,
            showCancelButton: false,
          });
          // alert(`${baseParams[paramsKey].title}未填写，请重新填写后提交`);
          return;
        }
      }
      
      
      this.files.forEach((file) => {
        if (file.raw) {
          params.append("files", file.raw, file.name);
        }
      });
      
      // 请求参数处理
      for (let paramsKey in baseParams) {
        // 带关联的部分需要加一层
        if (baseParams[paramsKey].relevance) {
          baseParams[paramsKey].relevance.forEach(item => {
            params.append(item.keys, item.value);
          });
        }
        params.append(paramsKey, baseParams[paramsKey].value);
      }
      params.append("reTourCheck", this.reTourCheck);
      params.append("serviceState", this.serviceState);

      params.append("delList", this.delList);
      
      let config = {
        headers: {"Content-Type": "multipart/form-data",Authorization: uni.getStorageSync('token') || ''}
      };
      let url = "";
      // #ifndef IGW
      url = "/ap/txksh/kosinManage/rest/api/fibercore/line_exam_save";
      // #endif
      // #ifdef IGW
      url = `${this.baseUrl}/txksh/kosinManage/rest/api/fibercore/line_exam_save`;
      // #endif

      console.log(url, "completeFiber----");
      
      Toast.loading({
        duration: 0,
        message: "加载中...",
        forbidClick: true,
      });
      
      axios.post(url, params, config)
        .then(response => {
          Toast.clear();
          
          if (response.data.code === 0) {
            // 如果当前为巡视，且返回data为0，表示重复巡视
            if (this.reTourCheck === "1" && response.data.data === 0) {
              Dialog.confirm({
                message: "该纤芯已被巡视，请返回重试",
              }).then(() => {
                this.goBack();
              });
            } else if (this.reTourCheck === '0'){
              // 重新编辑时无完善下一条选项
              Dialog.alert({
                title: "编辑成功",
                confirmButtonText: "返回列表",
              })
                .then(() => {
                  this.goBack();
                })
            } else {
              Dialog.confirm({
                title: "保存成功",
                confirmButtonText: "完善下一条",
                cancelButtonText: this.reTourCheck === '0' ? '': "返回列表",
              })
                // 完善下一条
                .then((res) => {
                  this.$api.todoTaskApi.continueExamine({
                    "fiber_exam_id": this.opticalInfo.PAR_OPT,
                    "lineSn": this.opticalInfo.CORE_NAME,
                  }).then(res => {
                    if (res.msg === "完毕") {
                      Dialog.confirm({
                        message: "此光缆所有纤芯信息已经全部完善！",
                        showCancelButton: false,
                        confirmButtonText: "返回列表",
                      }).then(() => {
                        this.goBack();
                      });
                      // alert("此光缆所有纤芯信息已经全部完善！");
                    } else {
                      uni.navigateTo({
                        url: `/pages/workBench/todoTask/cableTour/cableDetail/completeFiber?taskId=${this.taskId}&opticalInfo=${JSON.stringify(res.data)}&source=${this.pageSource}&reTourCheck=1`
                      });
                    }
                  });
                })
                // 返回列表
                .catch(() => {
                  this.goBack();
                });
            }
          } else {
            Dialog.alert({
              message: "操作失败",
              theme: "round-button",
            });
          }
          
          // if (response.data.msg === '成功') { // 提交成功
          //   Dialog.confirm({
          //     title: '保存成功',
          //     confirmButtonText: "完善下一条",
          //     cancelButtonText: "返回列表",
          //   })
          //     // 完善下一条
          //     .then((res) => {
          //       this.$api.todoTaskApi.continueExamine({
          //         "fiber_exam_id": this.opticalInfo.PAR_OPT
          //       }).then(res => {
          //         if (res.msg === "完毕") {
          //           Dialog.confirm({
          //             title: "此光缆所有纤芯信息已经全部完善！",
          //             showCancelButton: false,
          //             confirmButtonText: "返回列表",
          //           }).then(() => {
          //             this.goBack();
          //           })
          //           // alert("此光缆所有纤芯信息已经全部完善！");
          //         } else {
          //           uni.navigateTo({
          //             url: `/pages/workBench/todoTask/cableTour/cableDetail/completeFiber?taskId=${this.taskId}&opticalInfo=${JSON.stringify(res.data)}&source=${this.pageSource}&reTourCheck=1`
          //           });
          //         }
          //       });
          //     })
          //     // 返回列表
          //     .catch(() => {
          //       if (this.pageSource === "addCable") {
          //         uni.navigateTo({
          //           url: `/pages/workBench/todoTask/cableTour/addCable/addCable?taskId=${this.taskId}&fiber_exam_id=${this.opticalInfo.PAR_OPT}`
          //         });
          //       } else if (this.pageSource === "cableDetail") {
          //         uni.navigateTo({
          //           url: `/pages/workBench/todoTask/cableTour/cableDetail/cableDetail?tourId=${this.opticalInfo.PAR_OPT}`
          //         });
          //       }
          //     })
          // }
        });
    }
  },
};
</script>

<style scoped lang="scss">

.optical-complete-wrap {
  min-height: 100vh;
  background-color: #F8F8F8;
  
  .header {
    position: sticky;
    top: 0;
    z-index: 9;
  }
  
  .van-preview-wrap {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    
    .van-swipe {
      width: 100%;
      height: 60%;
    }
    
    img {
      height: 90%;
    }
  }
  
  /deep/ .picker-option {

    
    &.corepdId-picker {
      display: flex;
      justify-content: space-between;
      align-items: baseline;
      width: calc(100vw - 40px);
      
      .circuit {
        width: px2vw(750);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }

      .light-option {
        width: px2vw(750);
        word-break: break-all;
        
      }
    }
    &.lightName-picker {
      justify-content: center;
      width: 100vw;
      .light-option {
        display: flex;
        width: 100%;
        justify-content: center;
        font-size: 10px;

      }
    }

    &.other-picker {
      justify-content: center;
      width: 100vw;
      .default-option {
        display: flex;
        width: 100%;
        justify-content: center;
      }
    }
    
  }
  
  .main-container {
    //width: 100vw;
    //height: 100vh;
    padding: px2vh(30) px2vw(30) px2vh(90) px2vw(30);
    
    /deep/ .van-field__label,
    /deep/ .van-field__control,
    /deep/ .van-field__control:read-only {
      font-size: px2vw(42);
    }
    
    
    .base-info-container, .result-info-container {
      border-radius: $border-radius-base;
      overflow: hidden;
      background-color: #FFFFFF;
    }
    
    .optical-info-container {
      .optical-info-item {
        border-radius: $border-radius-base;
        overflow: hidden;
        background-color: #FFFFFF;
      }
      
      .optical-info-item {
        margin-top: px2vh(30);
      }
      
      .switch {
        /deep/ .van-field__label {
          width: auto;
        }
      }
      
      .end-item {
        /deep/ .van-collapse-item__content {
          padding: 0;
        }
        
        /deep/ .van-cell--large .van-cell__title {
          font-size: px2vw(42);
        }
        
        /deep/ .van-cell__left-icon {
          height: auto;
          line-height: 100%;
          
          .van-icon__image {
            width: px2vw(60);
            height: px2vw(60);
            vertical-align: middle;
          }
        }
        
        /deep/ .van-cell__left-icon {
          margin-right: px2vw(20);
        }
      }
    }
    
    .result-info-container {
      margin-top: px2vh(30);
    }
    
    .plate-title {
      margin-top: px2vh(30);
      margin-bottom: px2vh(27);
    }
    
    .plate-title-2 {
      margin-top: px2vh(60);
      margin-bottom: px2vh(27);
    }
    
    .remark-info-container {
      padding: px2vh(70) px2vw(50);
      font-size: px2vw(42);
      color: #666666;
      border-radius: $border-radius-base;
      overflow: hidden;
      background-color: #FFFFFF;
      margin-top: px2vh(30);
      
      .remark-wrap {
        background-color: #FAFAFA;
        padding: px2vh(41) px2vw(56) px2vh(77) px2vw(55);
        border-radius: px2vw(20);
        
        .remark-text {
          width: 100%;
          height: px2vh(150);
        }
      }
    }
    
    .patrol-info-container {
      margin-top: px2vh(30);
      padding: px2vh(70) px2vw(50);
      font-size: px2vw(42);
      color: #666666;
      border-radius: $border-radius-base;
      overflow: hidden;
      background-color: #FFFFFF;
      
      /deep/ .van-radio {
        margin-right: px2vw(139.5)
      }
      
      .image-wrap {
        width: 100%;
        display: flex;
        
        img {
          width: px2vw(215);
          height: px2vw(215);
          margin-right: px2vw(40);
          border-radius: px2vw(6);
        }
        
        .image-list {
          width: 100%;
          display: flex;
          
          .upload-button {
            width: px2vw(215);
            height: px2vw(215);
            background-size: cover;
            margin-right: px2vw(40);
            position: relative;
            
            .delete-icon {
              position: absolute;
              top: px2vw(-20);
              right: px2vw(-20);
              width: px2vw(40);
              height: px2vw(40);
              background-color: rgba(0, 0, 0, 0.7);
              border-radius: 50%;
              color: #fff;
              display: flex;
              justify-content: center;
              align-items: center;
            }
          }
        }
      }
    }
    
    /deep/ .van-button {
      margin-top: px2vh(70);
      height: px2vh(120);
      color: #fff;
      background-color: #417ADC;
      border: 1px solid #417ADC;
      border-radius: px2vh(60);
    }
  }
  
  /deep/ .van-uploader__upload-icon {
    text-align: center;
  }
}

</style>